package com.ruoyi.web.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.app.domain.bo.AppPackageTwoOrderBo;
import com.ruoyi.app.domain.vo.AppPackageTwoOrderVo;
import com.ruoyi.app.service.IAppPackageTwoOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 爬塔记录
 *
 * @author heise
 * @date 2025-06-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/packageTwoOrder")
public class AppPackageTwoOrderController extends BaseController {

    private final IAppPackageTwoOrderService iAppPackageTwoOrderService;

    /**
     * 查询爬塔记录列表
     */
    @SaCheckPermission("system:packageTwoOrder:list")
    @GetMapping("/list")
    public TableDataInfo<AppPackageTwoOrderVo> list(AppPackageTwoOrderBo bo, PageQuery pageQuery) {
        return iAppPackageTwoOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出爬塔记录列表
     */
    @SaCheckPermission("system:packageTwoOrder:export")
    @Log(title = "爬塔记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppPackageTwoOrderBo bo, HttpServletResponse response) {
        List<AppPackageTwoOrderVo> list = iAppPackageTwoOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "爬塔记录", AppPackageTwoOrderVo.class, response);
    }

    /**
     * 获取爬塔记录详细信息
     *
     * @param packageTorderId 主键
     */
    @SaCheckPermission("system:packageTwoOrder:query")
    @GetMapping("/{packageTorderId}")
    public R<AppPackageTwoOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long packageTorderId) {
        return R.ok(iAppPackageTwoOrderService.queryById(packageTorderId));
    }

    /**
     * 新增爬塔记录
     */
    @SaCheckPermission("system:packageTwoOrder:add")
    @Log(title = "爬塔记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppPackageTwoOrderBo bo) {
        return toAjax(iAppPackageTwoOrderService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改爬塔记录
     */
    @SaCheckPermission("system:packageTwoOrder:edit")
    @Log(title = "爬塔记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppPackageTwoOrderBo bo) {
        return toAjax(iAppPackageTwoOrderService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除爬塔记录
     *
     * @param packageTorderIds 主键串
     */
    @SaCheckPermission("system:packageTwoOrder:remove")
    @Log(title = "爬塔记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{packageTorderIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] packageTorderIds) {
        return toAjax(iAppPackageTwoOrderService.deleteWithValidByIds(Arrays.asList(packageTorderIds), true) ? 1 : 0);
    }
}
